<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Services\OSS;

class TestController extends Controller
{
    public function upload(Request $request){
        // 获取表单提交的图片
        //$pic = $request->file('pic');

       // $tes = getWxHead($request->input('test'));
        $url = $request->input('test');

        $img = getcurl($url);
        $pathName = pathName();
        $result = OSS::uploadContent($pathName, $img);
        $Url = OSS::getPublicObjectURL(config('alioss.aliyun_oss_bucket'), $pathName);
        //$Url->key;
        dd($Url);die;

        $ch = curl_init ($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); // 绕过ssl
        $img = curl_exec($ch);

        curl_close($ch);

        //dd($pic,$tes);

        //dd(fopen($pic, 'r'),fopen($tes, 'r'));
        //uploadContent($tes);
// 判断图片有效性
  /*      if (!$pic->isValid()) {
            return back()->withErrors('上传图片无效..');
        }*/
// 获取图片在临时文件中的地址
       // $pic = $pic->getRealPath();
// 制作文件名
        $pathName = time() . rand(10000, 99999999) . '.jpg';
//阿里 OSS 图片上传
        $result = OSS::uploadContent($pathName, $img);
        //获取上传图片的Url链接
        //$Url = OSS::getPublicObjectURL('Bucket名称', $pathName);
        if ($result) {
            // success
            dd($request->toArray());
        } else {
            // fail
            dd($request);
        }
    }
}
